let fs = require('fs');
const Payment = require('wxpay-v3');

const payment = new Payment({
  appid: 'wx6ade98a616eff449',
  mchid: '1305372501',
  private_key: require('fs').readFileSync('./config/wx_apiclient_key.pem').toString(),//或者直接复制证书文件内容
  serial_no: '20ECB3D561FA76F1F11C31B084976717C99D9C52',
  apiv3_private_key: 'thisisputaoxinxijishuyouxiangong',
  notify_url: "https://www.xiaowanwu.cn/txapi/wxpayNotify",
})


exports.pay = async function (price, orderNo, notifyUrl, returnUrl) {

  let result = await payment.h5({
    description: '测试支付',
    out_trade_no: orderNo,
    amount: {
      total: parseInt(price * 100)
    },
    scene_info: {
      payer_client_ip: '203.205.219.187'
    }
  })
  console.log(result)
  return result;
}


exports.getTransactionsById = async function (id) {
  let result = await payment.getTransactionsById({
    transaction_id: '0ce2d6a4-69a9-5f0b-b6de-5cffc81d6cd0'
  });
  console.log(result);
}
exports.decodeResource = function (resource) {
  let result = payment.decodeResource(resource)
  return result;
}
exports.close = async function (out_trade_no) {
  let result = await payment.close({
    out_trade_no: out_trade_no
  })
  return result;
}




